﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using GameSchoolWeb.Models;
using GameSchoolWeb.Controllers;
using GameSchoolWeb.Tests;


/// <summary>
/// MockCourseRepository býr til gervigögn fyrir prófanir á föllum í verkefninu.
/// Classinn erfir InterfaceCourseRepository og útfærir þau föll sem þörf er á fyrir 
/// einingarprófanir. Föll sem ekki eru notuð eru ekki útfærð.
///</summary>
namespace GameSchoolWeb.Tests.Controllers
{
    public class MockCourseRepository : ICourseRepository
    {
        #region Member variables

        // Býr til tilvik af clössum sem standa fyrir töflunar í SQL DB. Þá er hægt að herma eftir
        // virkni þeirra í TestControllerum.

        List<Course> m_courseItems = new List<Course>();
        List<Exam> m_examItems = new List<Exam>();
        List<Question> m_questionItems = new List<Question>();
        List<Level> m_levelItems = new List<Level>();
        List<NewsItem> m_newsItems = new List<NewsItem>();
        List<Assignment> m_assignmentItems = new List<Assignment>();
        List<Lecture> m_LectureItems = new List<Lecture>();
        List<Like> m_likeItems = new List<Like>();
        List<Comment> m_commentItems = new List<Comment>();
        List<TurninInAssignment> m_turnInAssignment = new List<TurninInAssignment>();
        List<TurnInExam> m_turnInExamItems = new List<TurnInExam>();
        List<ExamTurninQuestion> m_examTurninQuestionItems = new List<ExamTurninQuestion>();
        List<UserRegistration> m_userRegistrationItems = new List<UserRegistration>(); 
        #endregion

        public void Save()
        {
            // Enginn virkni hér viljandi.
        }

        // Constructor býr til gervi tilvik af öllu sem þarf að prófa. Notandi ræður hve mörg tilvik eru búin til. 
        public MockCourseRepository(int count)
        {
            MockCourses(count);
            MockLevels(count);
            MockAssignments(count);
            MockTurnInAssignment(count);
            MockExams(count);
            MockQuestions(count);
            MockNews(count);
            MockVideo(count);
            MockLecture(count);
            MockComment(count);
            MockLikes(count);
        }

        public MockCourseRepository(List<Course> Courses)
        {
            m_courseItems = Courses;
        }

        #region Courses
        /// <summary>
        /// Courses
        ///</summary>
        public void MockCourses(int count)
        {
            for (int i = 0; i < count; i++)
            {           // Bætir við notendum í samræmi við virkni í GameSchoolDB.dbml
                m_courseItems.Add(new Course
                {
                    id = i + 1,
                    strName = "TheAvengers:" + (i + 1),
                    strCourseDescription = "A group of osom heroes and hawk man",
                    strCourseMaster = "Nick Fury"
                });
            }
        }

        public IQueryable<Course> Courses()
        {
            return m_courseItems.AsQueryable();
        }

        public IQueryable<NewsItem> NewsItems()
        {
            return m_newsItems.AsQueryable();
        }

        public void AddUserRegistration(UserRegistration UregItem)
        {
            throw new NotImplementedException();
        }

        public void AddCourse(Course courseItem)
        {
            throw new NotImplementedException();
        }

        public void DeleteCourse(Course courseItem)
        {
            throw new NotImplementedException();
        }

        public void AddLevels(Level levelItem)
        {
            throw new NotImplementedException();
        }
        #endregion

        #region Exams
        /// <summary>
        /// Exam
        ///</summary>
        public void MockExams(int count)
        {
            for (int i = 0; i < count; i++)
            {
                m_examItems.Add(new Exam
                {
                    id = i + 1,
                    strTitle = "Próf " + (i + 1),
                    dDateAdded = DateTime.Now.AddDays(i),
                    nPoints = 1000,
                    levelId = i + 1

                });
            }
        }

        public IQueryable<Exam> Exams()
        {
            return m_examItems.AsQueryable();
        }

        public void AddExam(Exam ExamItem)
        {
            throw new NotImplementedException();
        }
        
        #endregion

        #region Questions
        /// <summary>
        /// Questions
        ///</summary>
        public void MockQuestions(int count)
        {
            for (int i = 0; i < count; i++)
            {
                m_questionItems.Add(new Question
                {
                    id = i + 1,
                    strTitle = "Er sindri fínn gaur? " + (i + 1),
                    striOptionOne = "Já",
                    strOptionTwo = "Nei",
                    strOptionThree = "Kannski",
                    strOptionFour = "Bæði 1 og 3",
                    strOptionFive = "Hef ekki hugmynd",
                    nNumber = i + 1,
                    examId = i,
                    nCorrectOption = 5
                });
            }
        }

        public IQueryable<Question> Questions()
        {
            return m_questionItems.AsQueryable();
        }


        public void AddQuestions(Question QuestionItem)
        {
            throw new NotImplementedException();
        }
        
        #endregion

        #region Levels
        /// <summary>
        /// Levels
        ///</summary>
        public void MockLevels(int count)
        {
            for (int i = 1; i < count; i++)
            {
                m_levelItems.Add(new Level
                {
                    id = i,
                    nLvlNumber = i,
                    courseId = i,
                });
            }
        }

        public IQueryable<Level> Levels()
        {
            return m_levelItems.AsQueryable();
        } 
        #endregion

        #region Assignments
        /// <summary>
        /// Assignments
        ///</summary>
        public void MockAssignments(int count)
        {
            for (int i = 0; i < count; i++)
            {
                m_assignmentItems.Add(new Assignment
                {
                    id = i + 1,
                    strTitle = "Assignment " + (i + 1),
                    strUrl = "http://www.hr.is",
                    strAssignmentDescription = "Assignment description",
                    dDateAdded = DateTime.Now.AddDays(i),
                    strValue = "value",
                    levelId = i + 1
                });
            }
        }

        public void MockTurnInAssignment(int count)
        {
            for (int i = 0; i < count; i++)
            {
                m_turnInAssignment.Add(new TurninInAssignment
                {

                    strTitle = "Assignment " + (i + 1),
                    nScore = i + 1,
                    dReturnDate = DateTime.Now.AddDays(i),
                    assignmentId = i + 1,
                    UserId = new Guid(),
                    strContent = "Assignment content",
                });
            }
        }

        public IQueryable<TurninInAssignment> TurnInAssignment()
        {
            return m_turnInAssignment.AsQueryable();
        }

        public IQueryable<Assignment> Assignments()
        {
            return m_assignmentItems.AsQueryable();
        }

        public void AddAssignment(Assignment assignmentItem)
        {
            //viljandi tómt
        }

        public void DeleteAssignment(Assignment assignmentItem)
        {
            throw new NotImplementedException();
        }

        public void TurnInAssignment(TurninInAssignment TurnInAssignment)
        {
            throw new ApplicationException("Reglu villa");
        }
        
        #endregion

        #region News
        /// <summary>
        /// News
        ///</summary>
        public void AddNews(NewsItem newsItem)
        {
            throw new NotImplementedException();
        }

        public void MockNews(int count)
        {
            for (int i = 0; i < count; i++)
            {
                m_newsItems.Add(new NewsItem
                {
                    id = i + 1,
                    strNewsTitle = "Halli náði gagnaskipan",
                    strNewsContent = "Allir féllu í gagnaskipan!",
                    dDateCreated = DateTime.Now.AddDays(i),
                    courseId = i + 1
                });
            }
        }
        
        #endregion

        #region Videos
        /// <summary>
        /// Video
        ///</summary>
        public void MockVideo(int count)
        {
            for (int i = 0; i < count; i++)
            {
                m_LectureItems.Add(new Lecture
                {
                    id = i + 1,
                    varTitle = "Title " + (i + 1),
                    strUrl = "http://www.youtube.com/watch?v=Q4VK9_CfOLQ",
                    strLectureDescription = "Gott lag maður!",
                    dDateAdded = DateTime.Now.AddDays(i),
                    // level id = ?
                });
            }
        }

        public void MockLecture(int count)
        {
            for (int i = 0; i < count; i++)
            {
                m_LectureItems.Add(new Lecture
                {
                    id = i + 1,
                    varTitle = "The Title is:" + (i + 1),
                    strUrl = "http://www.youtube.com/watch?v=Q4VK9_CfOLQ",
                    strLectureDescription = "Gott lag maður!!",
                    dDateAdded = DateTime.Now,
                    levelId = i + 1
                });
            }
        }

        public IQueryable<Lecture> Lecture()
        {
            return m_LectureItems.AsQueryable();
        }

        public void AddLecture(Lecture lectureItem)
        {
            throw new NotImplementedException();
        }

        public void DeleteLecture(Lecture lectureItem)
        {
            throw new NotImplementedException();
        }
        
        #endregion

        #region Comments
        /// <summary>
        /// Comments
        ///</summary>
        public void MockComment(int count)
        {
            for (int i = 0; i < count; i++)
            {
                m_commentItems.Add(new Comment
                {
                    id = i + 1,
                    strCommentText = "Þetta er athugasemd.",
                    dCommentDate = DateTime.Now.AddDays(i),
                    nUseful = i + 1,
                    lectureId = i + 1,
                    UserId = new Guid()
                });
            }
        }
        public IQueryable<Comment> Comments()
        {
            throw new NotImplementedException();
        }

        public void AddComment(Comment commentItem)
        {
            throw new NotImplementedException();
        }

        public void DeleteComment(Comment c)
        {
            throw new NotImplementedException();
        }
        
        #endregion

        #region Likes
        /// <summary>
        /// Likes
        ///</summary>
        public void MockLikes(int count)
        {
            for (int i = 0; i < count; i++)
            {
                m_likeItems.Add(new Like
                {
                    id = i + 1,
                    commentId = i,
                    UserId = new Guid()
                });
            }
        }

        public IQueryable<TurnInExam> TurnInExam()
        {
            return m_turnInExamItems.AsQueryable();
        }

        public IQueryable<ExamTurninQuestion> examTurninQuestionItems()
        {
            return m_examTurninQuestionItems.AsQueryable();
        }

        public IQueryable<UserRegistration> UserRegistrations()
        {
            return m_userRegistrationItems.AsQueryable();
        }

        public IQueryable<Like> Likes()
        {
            throw new NotImplementedException();
        }

        public void AddLike(Like likeItem)
        {
            throw new NotImplementedException();
        }

        public void AddTurnInExam(TurnInExam turnInExamItem)
        {
            throw new NotImplementedException();
        }

        public void DeleteExam(Exam examItem)
        {
            throw new NotImplementedException();
        }

        public void AddExamTurninQuestion(ExamTurninQuestion examTurninQuestionItem)
        {
            throw new NotImplementedException();
        } 
        #endregion
    }

  
}